package com.summerli.fallback;

import com.alibaba.fastjson.JSONObject;
import com.summerli.common.ResponseResult;
import com.summerli.common.sms.SmsSendRequest;
import com.summerli.feign.SmsClient;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class SmsClientFallbackFactory implements FallbackFactory<SmsClient> {

    @Override
    public SmsClient create(Throwable cause) {
        return new SmsClient() {
            @Override
            public ResponseResult sendSms(SmsSendRequest smsSendRequest) {
                log.info("--invoke SmsClient_sendSms exception request:" + JSONObject.toJSONString(smsSendRequest));
                return ResponseResult.fail(-3, "当前短信发送服务不可用，请稍后再试");
            }
        };
    }
}
